<?php

namespace app\admin\validate\setting;

use tmcore\base\BaseValidate;

/**
 * 存储配置验证器
 */
class StorageValidate extends BaseValidate
{

    protected $rule = [
        'status' => 'require',
        'identify' => 'require|checkIdentify',
    ];

    protected $message = [
        'status.require' => '状态不能为空',
        'identify.require' => '存储引擎参数不能为空',
    ];

    /**
     * 设置存储参数场景
     * @return StorageValidate
     */
    public function sceneEdit()
    {
        return $this->only(['identify','status']);
    }


    /**
     * 获取配置参数信息场景
     * @return StorageValidate
     */
    public function sceneDetail()
    {
        return $this->only(['identify']);
    }


    /**
     * 切换存储场景
     * @return StorageValidate
     */
    public function sceneChange()
    {
        return $this->only(['identify']);
    }

    /**
     * 检查存储标识
     * @param $value
     * @return bool|string
     */
    public function checkIdentify($value)
    {
        if(!in_array($value, ['local','aliyun','qiniu','qcloud'])) return '存储引擎参数错误';
        return true;
    }
}